package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.arg.LambdaArg;
import com.azier.kapacitor.script.method.*;
import com.azier.kapacitor.script.node.nodebind.*;
import com.azier.kapacitor.script.node.nodebind.qlnodebind.*;

import java.util.ArrayList;

/**
* 1 * @Author: luoj
* 2 * @Date: 2019/11/8 11:27
* 3
*/

/**
Combine this node with itself. The data is combined on timestamp.
**/
/**
将此节点与其自身结合。数据按时间戳合并。
**/
public class CombineNode extends AbstractNode implements AlertNodeBind, BarrierNodeBind, BottomNodeBind, ChangeDetectNodeBind, CombineNodeBind,
        CountNodeBind, CumulativeSumNodeBind, DefaultNodeBind, DeleteNodeBind, DerivativeNodeBind, DifferenceNodeBind, DistinctNodeBind,
        Ec2AutoscaleNodeBind, ElapsedNodeBind, EvalNodeBind, FirstNodeBind, FlattenNodeBind, GroupByNodeBind, HoltWintersNodeBind,
        HoltWintersWithFitNodeBind, HttpOutNodeBind, HttpPostNodeBind, InfluxDBOutNodeBind, JoinNodeBind, K8sAutoscaleNodeBind,
        KapacitorLoopbackNodeBind, LastNodeBind, MaxNodeBind, MeanNodeBind, MedianNodeBind, MinNodeBind, ModeNodeBind,
        MovingAverageNodeBind, PercentileNodeBind, SampleNodeBind, ShiftNodeBind, SideloadNodeBind, SpreadNodeBind, StateCountNodeBind,
        StateDurationNodeBind, StatsNodeBind, StddevNodeBind, SumNodeBind, SwarmAutoscaleNodeBind, TopNodeBind, UnionNodeBind, WhereNodeBind,
        WindowNodeBind {
    private static final String name = "combine";

    public CombineNode(String ...expressions) {
        super(new ArrayList<>(),new ArrayList<>(),name);
        //
        for(String argf : expressions){
            this.args.add(new LambdaArg(argf));
        }
    }

    /**
    Prefix names for all fields from the respective nodes. Each field from the parent nodes will be prefixed with the provided name and a ‘.’. See the example above.
    **/
    /**
    各个节点中所有字段的前缀名称。父节点的每个字段都将以提供的名称和“。”作为前缀。请参阅上面的示例。
    **/
    public CombineNode as(String ...names){
        As as = new As(names);
        super.addMethod(as);
        return this;
    }
    /**
    The delimiter between the As names and existing field an tag keys. Can be the empty string, but you are responsible for ensuring conflicts are not possible if you use the empty string.
    **/
    /**
    标签名称和现有字段之间的定界符。可以是空字符串，但是如果使用空字符串，您有责任确保不会发生冲突。
    **/
    public CombineNode delimiter(String combine){
        Delimiter delimiter = new Delimiter(combine);
        super.addMethod(delimiter);
        return this;
    }
    /**
    Maximum number of possible combinations. Since the number of possible combinations can grow very rapidly you can set a maximum number of combinations allowed. If the max is crossed, an error is logged and the combinations are not calculated. Default: 10,000
    **/
    /**
    可能的最大组合数。由于可能的组合数量会迅速增加，因此您可以设置允许的最大组合数量。如果超过最大值，则会记录错误，并且不会计算组合。默认值：10,000
    **/
    public CombineNode max(long combine){
        Max max = new Max(combine);
        super.addMethod(max);
        return this;
    }

    /**
    Suppress all error logging events from this node.
    **/
    /**
    禁止来自此节点的所有错误记录事件。
    **/
    public CombineNode quiet(){
        Quiet quiet = new Quiet();
        super.addMethod(quiet);
        return this;
    }
    /**
    The maximum duration of time that two incoming points can be apart and still be considered to be equal in time. The joined data point’s time will be rounded to the nearest multiple of the tolerance duration.
    **/
    /**
    两个进入点可以分开并且仍然被认为在时间上相等的最大持续时间。加入的数据点的时间将四舍五入到公差持续时间的最接近倍数。
    **/
    public CombineNode tolerance(long interval, String durationLiteral){
        Tolerance tolerance = new Tolerance(interval, durationLiteral);
        super.addMethod(tolerance);
        return this;
    }
}